package collection;

import java.util.Arrays;
import java.util.List;

public class ArrayToList {
    public static void main(String[] args) {
        String[] arr={"one","two","three","four","five"};
        System.out.println(Arrays.toString(arr));//[one, two, three, four, five]

        //asList()方法会返回内部的AarrayList,内部直接引用给定数组array
        List<String> list=Arrays.asList(arr);//[one, two, three, four, five]

        //对数组操作后,集合也会相应的改变
        arr[1]="six";
        System.out.println("arr:"+Arrays.toString(arr));//[one, six, three, four, five]
        System.out.println("list:"+list);//[one, six, three, four, five]

        //对集合操作后,数组也会做相应的改变
        list.set(2,"seven");//将集合的第三个元素修改为seven
        System.out.println("arr:"+Arrays.toString(arr));//[one, six, seven, four, five]
        System.out.println("list:"+list);//[one, six, seven, four, five]


        //list.add("333");//不可以增加元素
    }
}
